/*
 * MyMainFrame.java
 *
 * Created on __DATE__, __TIME__
 */

package main;

import java.awt.Component;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

import utils.Contents;
import utils.MessageBox;
import configuration.Configuration;

/**
 *
 * @author  __USER__
 */
public class MyMainFrame extends javax.swing.JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8331898284098419483L;
	/** Creates new form MyMainFrame */
	public MyMainFrame() {
		initComponents();
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {
		ImageIcon icon=new ImageIcon(Contents.ICON_PATH);//
		setIconImage(icon.getImage());
		panel1 =new GetPanel(872,567,System.getProperty("user.dir")+"/picture/bg/Mainframe2.jpg");
		this.setContentPane(panel1);
		jButton1 = new javax.swing.JButton();
		jButton2 = new javax.swing.JButton();
		jButton3 = new javax.swing.JButton();
		jButton4 = new javax.swing.JButton();
		
		setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
		getContentPane().setLayout(null);

		panel1.setLayout(null);
		panel1.setBounds(0, 0, 0, 0);
		jLable1 = new JLabel();
		jLable1.setText("<html><H2>&nbsp;&nbsp;欢迎使用矩阵运算教学辅助系统</H2><br><H2>请根据使用情况选择相应按钮进入对应功能<br>如有不明白的请参阅使用文档或查看联机文档</h2></html>");
		jLable1.setBounds(30,100,800,200);
		panel1.add(jLable1);
		panel1.add(jButton1);
		jButton1.setBounds(30, 320, 160, 40);
		jButton1.setIcon(new ImageIcon(System.getProperty("user.dir")+"/picture/button_img/001.jpg"));

		panel1.add(jButton2);
		jButton2.setBounds(220, 320,160, 40);
		jButton2.setIcon(new ImageIcon(System.getProperty("user.dir")+"/picture/button_img/002.jpg"));

		panel1.add(jButton3);
		jButton3.setBounds(410, 320, 160, 40);
		jButton3.setIcon(new ImageIcon(System.getProperty("user.dir")+"/picture/button_img/003.jpg"));

		panel1.add(jButton4);
		
		jButton4.setIcon(new ImageIcon(System.getProperty("user.dir")+"/picture/button_img/004.jpg"));
		jButton4.setBounds(600, 320, 160, 40);
		//监听
		jButton1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				int imgcount = 0;
				cg = new Configuration(Contents.CONFIG_PATH);
				if(!"".equals(cg.getValue("imgCount_Huan"))){
					imgcount = Integer.parseInt(cg.getValue("imgCount_Huan"));
				}
				Huandeng huandeng =  Huandeng.getInstance(imgcount);
				huandeng.setVisible(true);
				
			}
		});
		jButton2.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent arg0) {
				int imgCount = 0;
				cg = new Configuration(Contents.CONFIG_PATH);
				if(!"".equals(cg.getValue("imgCount_Matrix"))){
//					System.out.println(cg.getValue("imgCount_Matrix"));
					imgCount= Integer.parseInt(cg.getValue("imgCount_Matrix"));
				}
				Matrix_Change matriChange = Matrix_Change.getInstance(imgCount);
				matriChange.setVisible(true);
			}
		});
		jButton3.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0){
				
				Matrix_operations mo = Matrix_operations.getInstance();
				mo.setBounds(300, 150, 680, 505);
				mo.setResizable(false);
				mo.setVisible(true);
			}
		});
		jButton4.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0){
				DingY dy = DingY.getInstance();
				dy.setBounds(345, 187, 590, 425);
				dy.setVisible(true);
			}
		});
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e){
				if(MessageBox.Show("确定退出？", 12)==0){
					System.exit(0);
				}
			}
		});
		//为所有的component设置字体
		for(Component c:panel1.getComponents()){
			c.setFont(f);
		}
		//单独位为jLabel1设置特殊大小的字体
		pack();
	}// </editor-fold>
	//GEN-END:initComponents

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				MyMainFrame	mymf = new MyMainFrame();
				mymf.setVisible(true);
				mymf.setSize(880, 580);
			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton jButton1;
	private javax.swing.JButton jButton2;
	private javax.swing.JButton jButton3;
	private javax.swing.JButton jButton4;
	private javax.swing.JLabel	jLable1;
	private javax.swing.JPanel panel1;
	private Font f = new Font("宋体",Font.PLAIN,12);
	private Configuration cg ;
	// End of variables declaration//GEN-END:variables

}